package cn.eweb.ttkt;

import android.app.TabActivity;
import android.content.Intent;
import android.os.Bundle;
import android.widget.RadioGroup;
import android.widget.TabHost;
import android.widget.RadioGroup.OnCheckedChangeListener;

@SuppressWarnings("deprecation")
public class MainTab extends TabActivity {
	private RadioGroup group;
	private TabHost tabHost;
	public static final String TAB_HOME="tab_home";
	public static final String TAB_VIDEO="tab_video";
	public static final String TAB_MAP="tab_map";
	public static final String TAB_ABOUT="tab_about";
	
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.maintabs);
		
		tabHost = getTabHost();
		tabHost.addTab(tabHost.newTabSpec(TAB_HOME)
				.setIndicator(TAB_HOME)
	            .setContent(new Intent(this,HomeActivity.class)));
	    tabHost.addTab(tabHost.newTabSpec(TAB_VIDEO)
	            .setIndicator(TAB_VIDEO)
	            .setContent(new Intent(this,VideoActivity.class)));
	    tabHost.addTab(tabHost.newTabSpec(TAB_MAP)
                .setIndicator(TAB_MAP)
                .setContent(new Intent(this,MyMapActivity.class)));
	    tabHost.addTab(tabHost.newTabSpec(TAB_ABOUT)
                .setIndicator(TAB_ABOUT)
                .setContent(new Intent(this,AboutActivity.class)));
		
	    setGroup();
		
	}
	
	private void setGroup(){
		
		group = (RadioGroup)findViewById(R.id.main_radio);
	    group.setOnCheckedChangeListener(new OnCheckedChangeListener() {
			public void onCheckedChanged(RadioGroup group, int checkedId) {
				switch (checkedId) {
				case R.id.radio_button_1:
					tabHost.setCurrentTabByTag(TAB_HOME);
					break;
				case R.id.radio_button_2:
					tabHost.setCurrentTabByTag(TAB_VIDEO);
					break;
				case R.id.radio_button_3:
					tabHost.setCurrentTabByTag(TAB_MAP);
					break;
				case R.id.radio_button_4:
					tabHost.setCurrentTabByTag(TAB_ABOUT);
					break;
				default:
					break;
				}
			}
		});
	    group.check(R.id.radio_button_1);
	}
	

//	@Override
//	public void onConfigurationChanged(Configuration newConfig) {
//		setContentView(R.layout.maintabs);
//		setGroup();
//		super.onConfigurationChanged(newConfig);
//		Log.e("test", "onConfigurationChanged");
//		if(newConfig.orientation==Configuration.ORIENTATION_LANDSCAPE){
//			Log.e("test", "LANDSCAPE");
//			if(tabHost.getCurrentTabTag().equals(TAB_VIDEO)){
//				Log.e("test", "video");
//			}
//		}
//	}
    
}
